<?

/**
* Use $_SESSION["GDate"] if you are using custom date
* or just use the system date
*
* $today_date = $_SESSION["GDate"];
* $today_date = date("d-m-Y");
*
*/
$today_date		  = date("d-m-Y");

$srcDbHdr    = "MST_MODEL";
$srcDbDtl    = "MST_MODEL_COMPOS";
$srcDbHdrLog = "LOG_MST_MODEL";

$UID     = unserialize($_SESSION["serUID"]);
$userId  = $UID->getUID();

$Db = new oracleDb;
$Db->init($_SESSION["ORCL"],
           $_SESSION["OPASS"],
           $_SESSION["SID"],
           _NO_COMMENT);

if($Db->connect()){

	/**
	* Delete the previous entry
	*
	*/
	$CLHandlers->dbEntDelete($Db,
            	             $_SESSION["jid"],
            	             $srcDbDtl);

  $CLFetchers->fetchModelId($Db,
                            $_POST["modelEnt"],
                            $srcDbHdr,
                            $modelId);

  for($iRow = 0; $iRow < $dataup; $iRow++){

    $CLFetchers->fetchModelId($Db,
                              $_POST["composEnt"][$iRow],
                              $srcDbHdr,
                              $composModelId);

    $values = " '".$modelId."',               ".
              "  ".($iRow + 1)." ,            ".
              " '".$composModelId."',         ".
              "  ".$_POST["qtyEnt"][$iRow]."  ";

    $CLHandlers->insToDtl($Db,
                          $values,
                          $srcDbDtl);
  }

	$Db->commit();

	if($Db->getStatus() == true){

	  $Misc->usrMsg("Modify Complete");
	}else{

	  $Misc->usrDieJs("Modify Process Interupted");
	}

	$Db->dc();

	/**
	* Pending...
	* I'm not sure if this
	* reset procedure off
	* causes buggy
	*
	*	$restore  = 0;
	* $uprun    = 0;
	* $dataup   = 0;
	*
	*/
	//jumpTo(2,"../".$_SESSION["source_caller"]);

}else{

	$Misc->usrDieJs("Db connection failed");
}

?>